



let BaseAnimView  = require('./baseAnimView');

const templateDiv = `
     <label>绝对缩放</label><br/>
    <label>目标位置</label>
    sx:<input class="scale_x mini_input" type="number" step="0.1">
    sy:<input class="scale_y mini_input" type="number" step="0.1"> <br/>
    <label>时间</label>
    <input class="time mini_input" type="number" step="0.02" min="0.02"><br/>
    <button class="btnPlay">播放</button>
    <button class="btnStop">停止</button>
    <button class="btnDelete">删除</button>
    <label class="info"></label>
`;

let doubleBind = require('../../doubleBind');
// let settings = require('./../../settings');
let animUtils = require('./animUtils');
class ScaleToView extends BaseAnimView{
    constructor(){
        super(templateDiv);
    }

    bindModel(){
        let self = this;
        let lst = [];
        lst.push({
            el:this.rootEl.querySelector('.scale_x'),
            name:'sx',
            domName:'input',
            bNumber:true,
            callback:function () {
                let model = editor.getInspectView().getModel();
                if(model.anims){
                    model.anims.dx = self.model.sx;
                }
            }
        });
        lst.push({
            el:this.rootEl.querySelector('.scale_y'),
            name:'sy',
            domName:'input',
            bNumber:true,
            callback:function () {
                let model = editor.getInspectView().getModel();
                if(model.anims){
                    model.anims.dy = self.model.sy;
                }
            }
        });
        lst.push({
            el:this.rootEl.querySelector('.time'),
            name:'time',
            domName:'input',
            bNumber:true,
            callback:function () {
                let model = editor.getInspectView().getModel();
                if(model.anims){
                    model.anims.time = self.model.time;
                }
            }
        });

        this.model = {};
        lst.forEach(item=>{
            doubleBind(this.model,item);
        });
    }

    reset(){
        /**
         * 表示 动画 rotateBy 角度30 会耗费 1s
         * 那么 整个动画过程就是:
         *  RepectForever(Sequence(A->B->A)
         *  其中 A->B 的时间就是 1s
         *
         */
        this.model.sx = 1.06;
        this.model.sy = 1.06;
        this.model.time = 1;
    }

    _playAnim(selectSp){

        let inspAnimView = editor.getInspAnimView();
        inspAnimView.saveInitData();

        // 1. 删除之前的
        let actionMgr = cc.director.getActionManager();
        actionMgr.removeActionByTag(G.Tags.DecoBaseAction,selectSp.node);

        // 2. 创建动画,并进行播放
        let initSx = selectSp.sx;
        let initSy = selectSp.sy;
        let time = this.model.time;
        let sx = this.model.sx;
        let sy = this.model.sy;
        // let zoomIn = dd.scaleTo(time,sx,sy);
        // let zoomOut = dd.scaleTo(time * 2,2 * initSx - sx,2 * initSy - sy);
        // let z3 = dd.scaleTo(time,initSx,initSy);
        // let seq = dd.sequence(zoomIn,zoomOut,z3);
        // let forever = dd.repeatForever(seq);
        let forever = animUtils.makeScaleTo(time,initSx,initSy,sx,sy);
        selectSp.node.runAction(forever);

        this.updateInfoLabel();
    }
    // updateInfoLabel(){
    //     let selectSp = editor.getInspectView().getSelectedSp();
    //     if(selectSp){
    //         let actionMgr = cc.director.getActionManager();
    //         let action =  actionMgr.getActionByTag(G.Tags.DecoBaseAction,selectSp.node);
    //         if(action){
    //             this.lbInfo.textContent = '动画中.....';
    //             this.lbInfo.style.color = 'red';
    //             return;
    //         }
    //     }
    //
    //     this.lbInfo.textContent = '停止';
    //     this.lbInfo.style.color = 'black';
    // }
}


module.exports = ScaleToView;
